package Day07.deno3;

import Day07.demo2.Student;

import java.beans.beancontext.BeanContext;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @author chihb
 * @create-time 2024/7/4 11:57
 * @description
 */
public class Test {
    public static void main(String[] args) {
        List<User> list=new ArrayList<>();
        list.add(new User("小明", "123"));
        list.add(new User("小红", "456"));
        list.add(new User("小勇", "789"));
        Scanner sc=new Scanner(System.in);
        while (true) {
            System.out.println("请输入用户名：");
            String username=sc.next();
            boolean b=isUser(username,list);
            if(b){
                System.out.println("请输入密码：");
                String userPwd=sc.next();
                list.add(new User(username,userPwd));
                System.out.println("用户注册成功");
                break;
            }
        }
        list.forEach(System.out::println);
    }

    private static boolean isUser(String username, List<User> list) {
        for (int i = 0; i < list.size(); i++) {
            if(list.get(i).getName().equals(username)){
                System.out.println("用户已经存在，请重新输入");
                return false;
            }
        }
        return true;
    }
}
